package com.mxx.common.model;

import com.mxx.common.exception.UnsupportedTypeException;

/**
 * @Author itzgyw
 * @Date 2020-01-10
 * @Time 15:11
 * @Description:
 */
public interface EnumTemp<T extends Enum> {


    default boolean support(String name) {
        for (T t : getValues()) {
            if (t.name().equals(name)) {
                return true;
            }
        }
        return false;
    }

    default T convert(String name) throws UnsupportedTypeException {
        for (T t : getValues()) {
            if (t.name().equals(name)) {
                return t;
            }
        }
        throw new UnsupportedTypeException("Unsupported enumeration type :" + name);
    }

    T[] getValues();
}
